package sys.service.Impl;

import com.github.pagehelper.PageHelper;
import com.thread.MsgThread;
import com.util.BeanUtil;
import com.util.PagedResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sys.mapper.MsgMapper;
import sys.mapper.UserEmailMapper;
import sys.model.UserEmail;
import sys.service.EmailService;

import java.util.Map;

/**
 * Created by shugen on 2017/2/20.
 */
@Service
public class EmailServiceImpl implements EmailService {
    @Autowired
    UserEmailMapper userEmailMapper;
    @Autowired
    MsgMapper msgMapper;
    public int insert(UserEmail record) {
        int id=msgMapper.insert(record.getMsg());
        if (id>0){
            record.setMsgid(record.getMsg().getId());
            int j=userEmailMapper.insert(record);
            if(j>0){
                (new MsgThread(record)).start();   //启动线程   通知 接受者
            }
            return j;
        }
       else return 0;
    }

    public PagedResult<UserEmail> getEmailBox(Map map){
        PageHelper.startPage((Integer) map.get("page"),(Integer)map.get("rows"));  //分页参数
        return BeanUtil.toPagedResult(userEmailMapper.getEmailBox(map));
    }

    public int update(UserEmail record){
        return userEmailMapper.updateStatus(record);
    }
    public int delete(Map map){
        return userEmailMapper.updateStatus2(map);
    }
}
